function homeClick() {
    window.location.href="home/index.html";
}//跳转主页页面
function friendClick() {
    window.location.href="friend/index.html"
}//跳转好友页面
function spaceClick() {
    window.location.href="space/index.html";
}//跳转空间页面
function salaClick() {
    window.location.href="sala/index.html";
}//跳转大厅页面
function userCenterClick() {
    window.location.href="userCenter/index.html";
}//跳转用户中心页面

const Parent= {
    extends: TopParent,
    methods: {
        handleSelect(key, keyPath) {
            console.log(key, keyPath);
            this.selectMyUser();
            if(this.myUser.account==="") {
                alert("请先登录！");
                return;
            }
            switch(key) {
                case '5-1': {
                    window.location.href="userCenter/index.html";
                    break;
                }
                case '5-2': {
                    this.msgCenterDrawer = true;
                    break;
                }
            }
        },//标题栏点击事件
        logIn() {
            var _this = this;
            //为空
            if(_this.logInForm.accountOrEmail === null) {
                this.$message.error('账号或邮箱不能为空！');
                return;
            }
            else if(_this.logInForm.password === null) {
                this.$message.error('密码不能为空！');
                return;
            }
            axios({
                method:"get",
                url:ParentUrl+"/LogIn",
                params: {
                    accountOrEmail: _this.logInForm.account,
                    password: _this.logInForm.password
                }
            }).then(resp=>{
                //设置表格数据
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    this.$message({
                        message: '登录成功！',
                        type: 'success'
                    });
                    //关闭登录对话框
                    _this.logInDrawer=false;
                    //重新初始化页面
                    _this.init();
                }
                else {
                    this.$message({
                        message: '登录失败！',
                        type: 'warning'
                    });
                }
            });
        },//登录
        register() {
            var _this = this;
            //为空
            if(_this.registerForm.username === null) {
                this.$message.error('用户名不能为空！');
                return;
            }
            else if(_this.registerForm.password1 === null || _this.registerForm.password2 === null) {
                this.$message.error('密码不能为空！');
                return;
            }
            //密码不同
            else if (_this.registerForm.password1 !== _this.registerForm.password2) {
                this.$message.error('两次密码不同！');
                return;
            }
            axios.post(ParentUrl+"/LogIn", _this.registerForm).then(resp=>{
                //设置表格数据
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    this.$message({
                        message: '注册成功！',
                        type: 'success'
                    });
                    this.$notify({
                        title: '小V助手',
                        dangerouslyUseHTMLString: true,
                        message: '恭喜注册成功！<p>你的账号为：'+_this.Result.data.account+'。<p>请妥善保存！',
                        duration: 0
                    });
                    _this.activeName = '1';
                }
                else if(_this.Result.code===Code.PASSWORD_FORMAT_NO) {
                    this.$message({
                        message: '密码格式不正确！',
                        type: 'warning'
                    });
                }
                else if(_this.Result.code===Code.EMAIL_ALREADY_EXISTS) {
                    this.$message({
                        message: '邮箱已被使用，请尝试忘记密码或者使用其它邮箱！',
                        type: 'warning'
                    });
                }
                else {
                    this.$message.error('注册失败！');
                }
            });
        },//注册
        exitAccount() {
            var _this = this;
            axios({
                method:"delete",
                url:ParentUrl+"/LogIn",
            }).then(resp=>{
                //设置表格数据
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    document.cookie.repeat();

                    this.$message({
                        message: '已退出',
                        type: 'success'
                    });
                    //刷新用户信息
                    window.location.href=ParentUrl;
                }
                else {
                    this.$message({
                        message: '退出失败！',
                        type: 'warning'
                    });
                }
            })
        },//退出账号
        selectMyUser() {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/LogIn/selectMyUser",
            }).then(resp=>{
                //设置表格数据
                _this.Result = resp.data;
                if(_this.Result.code !== 0) {
                    _this.myUser = _this.Result.data;
                } else {
                    var account = getCookie("accountOrEmail");
                    var password = getCookie("password");
                    if(account===""||password==="") {
                        _this.logInDrawer = true;
                        return;
                    }
                    axios({
                        method:"get",
                        url:ParentUrl+"/LogIn",
                        params: {
                            accountOrEmail: account,
                            password: password
                        }
                    }).then(resp=>{
                        //设置表格数据
                        _this.Result = resp.data;
                        if(_this.Result.code === 1) {
                            //关闭登录对话框
                            _this.logInDrawer=false;
                            //重新初始化页面
                            _this.init();
                        }
                        else {
                            _this.logInDrawer = true;
                        }
                    });
                }
            })
        },//查询登录账户信息
        ackModifyUsername() {
            var _this = this;
            _this.user.username = _this.modifyUsernameForm.newUsername;
            _this.user.account = _this.modifyUsernameForm.account;
            _this.user.password = _this.modifyUsernameForm.password;
            axios({
                method:"put",
                url:ParentUrl+"/User/1",
                data:_this.user
            }).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.selectMyUser();
                    _this.modifyUsernameDrawer = false;
                    this.$message({
                        message: '名称修改成功！',
                        type: 'success'
                    });
                }else {
                    this.$message.error('名称修改失败！');
                }
            })
        },//修改名称
        ackModifyPassword() {
            if (this.modifyPasswordForm.oldPassword===null||this.modifyPasswordForm.newPassword1===null||this.modifyPasswordForm.newPassword2===null) {
                this.$message.error('两次新密码不同！');
                return;
            }
            else if (this.modifyPasswordForm.newPassword1 !== this.modifyPasswordForm.newPassword2) {
                this.$message.error('两次新密码不同！');
                return;
            }
            var _this = this;
            axios({
                method:"put",
                url:ParentUrl+"/User/2",
                params: {
                    oldPassword: _this.modifyPasswordForm.oldPassword,
                    newPassword: _this.modifyPasswordForm.newPassword1
                }
            }).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.modifyPasswordDrawer = false;
                    this.$message({
                        message: '密码修改成功！',
                        type: 'success'
                    });
                }
                else if(_this.Result.code===Code.PASSWORD_FORMAT_NO) {
                    this.$message.error('密码格式不正确');
                }
                else {
                    this.$message.error('密码修改失败！');
                }
            })
        },//修改密码
        forgotPassword() {
            if (this.forgotPasswordForm.password1===null||this.forgotPasswordForm.password2===null) {
                this.$message.error('两次新密码不同！');
                return;
            }
            var _this = this;
            axios({
                method:"put",
                url:ParentUrl+"/LogIn",
                params: {
                    email: _this.forgotPasswordForm.email,
                    captcha: _this.forgotPasswordForm.captcha,
                    password: _this.forgotPasswordForm.password1
                }
            }).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    this.$message({
                        message: '密码修改成功！',
                        type: 'success'
                    });
                    _this.logInForm.account = _this.forgotPasswordForm.email;
                    _this.activeName = '1';
                }
                else if(_this.Result.code===Code.PASSWORD_FORMAT_NO) {
                    this.$message.error('密码格式不正确');
                }
                else {
                    this.$message.error('密码修改失败！');
                }
            });
        }//忘记密码
    },
    data() {
        return {
            logInDrawer: false,//登录注册抽屉
            modifyUsernameDrawer: false,//修改名称对话框
            modifyPasswordDrawer: false,//修改密码对话框
            userDrawer: false,//用户
            logInForm: {
                account:'',
                password:''
            },//登录表单
            registerForm: {
                username:'',
                password1:'',
                password2:''
            },//注册表单
            forgotPasswordForm: {
                email: '',
                captcha: '',//验证码
                password1:'',
                password2:''
            },//忘记密码表单
            modifyUsernameForm: {
                account: '',
                password: '',
                newUsername: ''
            },//修改名称表单
            modifyPasswordForm: {
                oldPassword: '',
                newPassword1: '',
                newPassword2: ''
            },//修改密码表单
            myUser : {},//用户信息
            activeName: '1',//登录注册位置
            user: {
                id: '',
                email: '',
                username:'',
                account:'',
                password:''
            },
            sendCaptchaBtnDis: false,//发送验证码按钮是否禁用
            sendCaptchaBtnValue: '发送验证码'//发送验证码按钮内容
        };
    }
}